/*
* @Author: xfy
* @Date:   2017-08-26 18:18:26
* @Last Modified by:   xfy
* @Last Modified time: 2017-08-29 09:59:17
*/
'use strict';
require('./index.css');
var _supper = require('util/supper.js');
var _user = require('service/user-service.js');
//导航
var nav = {
    init : function(){
        this.bindEvent();
        this.loadUserInfo();
        return this;
    },
    bindEvent : function(){
        //登录点击事件
        $('.js-login').click(function(){
            _supper.doLogin();
        });
        //注册点击事件
        $('.js-register').click(function(){
            window.location.href = './user-register.html';
        });
        //退出点击事件
        $('.js-logout').click(function(){
            _user.logout(function(res){
                window.location.reload();
            }, function(errMsg){
                _supper.errorTips(errMsg);
            });
        });
    },
    //加载用户信息
    loadUserInfo : function(){
        _user.checkLogin(function(res){
            //登录成功就隐藏
            $('.user.not-login').hide().siblings('.user.login').show()
                .find('.username').text(res.userName);

            $('#idNo').text(res.idNo);
            $('.nav-list .attendance').attr('href', './attendance.html?idNo=' + res.idNo);
            $('.nav-list .message').attr('href', './user-center-update.html?idNo=' + res.idNo);
        }, function(errMsg){
        });
    },
}
module.exports = nav.init();